<?php

/**
 * This is the model class for table "zy_service".
 *
 * The followings are the available columns in table 'zy_service':
 * @property integer $service_id
 * @property string $service_name
 * @property string $code
 */
class Service extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Service the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_service';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('service_name,code','required'),
			array('service_name,code','unique'),
			array('service_name, code', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('service_id, service_name, code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'service_id' => Yii::t('base','Service_id'),
			'service_name' => Yii::t('base','Service Name'),
			'code' => Yii::t('base','code'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('service_id',$this->service_id);
		$criteria->compare('service_name',$this->service_name,true);
		$criteria->compare('code',$this->code,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function getServiceName($id)
	{
		$service = Service::model()->findByPk($id);
		return $service->service_name;
	}
	public function getAllService()
	{
		$returnArr = Service::model()->findAll();
		return CHtml::listData($returnArr,'service_id','service_name');
	}
	public function getServiceId($servicename)
	{
		if($servicename!="")
		{
			$sql = "select service_id from zy_service where service_name ='".$servicename."'";
			$connection = Yii::app()->db;
			$command = $connection->createCommand($sql);
			$results = $command->queryAll();
			for($i=0;$i<count($results);$i++){
				$result[$i]=$results[$i]['service_id'];
			}
			return $result;
		}
	}
	
}